package cn.sinonet.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import jt.classic.system.group.timmer.GroupMapScriptTimmer;
import jt.classic.system.init.Mounting;
import jt.classic.system.init.SystemMounting;
import jt.classic.system.table.timmer.TableDataBackupTimmer;
import jt.classic.system.user.timer.UserCenterTimer;

import org.limp.mine.DateTrimmer;

public class SystemContextListener implements ServletContextListener {

	private GroupMapScriptTimmer gmsTimmer;
	private TableDataBackupTimmer tdbTimmer;
	private UserCenterTimer userTimer;

	public SystemContextListener() {
		gmsTimmer = new GroupMapScriptTimmer(5000L, -1L);
		tdbTimmer = new TableDataBackupTimmer(6000L, -1L);
		userTimer = new UserCenterTimer(7000L, -1L);
	}

	public void contextDestroyed(ServletContextEvent arg0) {
		gmsTimmer.stopTask();
		tdbTimmer.stopTask();
		userTimer.stopTask();
		Mounting system = SystemMounting.getInstance();
		try {
			system.unmount();
		} catch (Exception ex) {
			ex.printStackTrace(System.out);
		}
		System.err.println((new StringBuilder(String.valueOf(DateTrimmer
				.getYMDHMS_LBL(DateTrimmer.getYMDHMS())))).append(
				"e-system say bye-bye,have a good time.").toString());
	}

	public void contextInitialized(ServletContextEvent arg0) {
	}
}
